﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace NETCORE.SQLITE.Utilize.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        private readonly MyToDoContext DB;
        public ValuesController(MyToDoContext myToDoContext)
        {
            DB = myToDoContext;
        }

        [HttpGet]
        public async Task<IActionResult> Get()
        {
            var list = await DB.ToDo.ToListAsync();
            return Ok(list);
        }

        [HttpPost]
        public async Task<IActionResult> Add()
        {
            var list = new List<ToDo>();

            for (int i = 0; i < 5; i++)
            {
                var model = new ToDo()
                {
                    Title = GetNameHelper.GetManName(),
                    Content = GetNameHelper.GetWomanName(),
                    Status = 1,
                };
                list.Add(model);
            }
            await DB.ToDo.AddRangeAsync(list);
            var res = await DB.SaveChangesAsync();
            return Ok(res);
        }
    }
}
